<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/13 0013
 * Time: 上午 9:17
 */
namespace app\common\lib;
require VENDOR_PATH.'sms/src/index.php';



use Qcloud\Sms\SmsSingleSender;
use Qcloud\Sms\SmsMultiSender;
use Qcloud\Sms\SmsVoiceVerifyCodeSender;
use Qcloud\Sms\SmsVoicePromptSender;
use Qcloud\Sms\SmsStatusPuller;
use Qcloud\Sms\SmsMobileStatusPuller;

use Qcloud\Sms\VoiceFileUploader;
use Qcloud\Sms\FileVoiceSender;
use Qcloud\Sms\TtsVoiceSender;
use think\Exception;

class Sms{
    protected $appId;
    protected $appKey;
    protected $smsSign = '';
    protected $templateId = '';
    function __construct()
    {
        $this->appId = config('sms.AppID');
        $this->appKey = config('sms.AppKey');
        $this->smsSign = config('sms.Sign');
        $this->templateId = config('sms.templateId');
    }

    //发送短信
    public function send($phone){
        try{
            $ssender = new SmsSingleSender($this->appId,$this->appKey);
            $key = randString(4);
            $params = [$key];
            $result = $ssender->sendWithParam("86",$phone,$this->templateId,$params,$this->smsSign,"","");
            $data = json_decode($result,true);
            $data['code'] = $key;
            return $data;
        }catch (Exception $e){
            return false;
        }



    }
}